package com.github.starry.fw.social.web.spider.wechat.tasklet;

import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.starry.fw.generator.java.api.GeneratorJavaService;
import com.github.starry.fw.generator.java.generator.JavaFile;
import com.github.starry.fw.generator.java.generator.JavaTypeUtil;
import com.github.starry.fw.generator.java.generator.command.JavaBeanClass;

@Component
public class CreateJavaTasklet implements Tasklet {

    private static final Logger logger = LoggerFactory.getLogger(CreateJavaTasklet.class);

    @Autowired
    private GeneratorJavaService generatorJavaService = null;

    public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {

        List<JavaFile> javaFileList = new ArrayList<JavaFile>();

        JavaBeanClass javaClassBean1 = new JavaBeanClass("TestBean" , "javaClassBean1");
        javaClassBean1.addField(JavaTypeUtil.createString(), "stringField", "stringFieldComment");
        javaClassBean1.addField(JavaTypeUtil.createInt(), "intField", "intFieldComment");
        javaClassBean1.addField(JavaTypeUtil.createArrayListString(), "listField", "listFieldComment");

        javaFileList.add(new JavaFile("com.github.test",javaClassBean1));

        generatorJavaService.createJava(javaFileList,"D:/Temp/20160927");
        return RepeatStatus.FINISHED;
    }


}